/*******************************************************************************
* This file implements the quaternion to calculate the attitude base on the
* data from the IMU.
*
* Author: Kong Wai Weng @ Cytron Technologies Sdn. Bhd.
*******************************************************************************/



#ifndef _QUAT_H
#define _QUAT_H



#include <math.h>
#include "system.h"
#include "variables.h"
#include "task.h"
#include "hal_sensors.h"



/*******************************************************************************
* STRUCTURE AND UNION DEFINITION                                               *
*******************************************************************************/

// Attitude of the aircraft.
// Unit = radian.
struct ATTITUDE{
	float fRoll;		// Range: -PI to PI.
	float fPitch;		// Range: -0.5PI to 0.5PI.
	float fYaw;			// Range: 0 to 2PI.
	
	float fRateX;		// Unit: rad/s.
	float fRateY;		// Unit: rad/s.
	float fRateZ;		// Unit: rad/s.
};



/*******************************************************************************
* PUBLIC FUNCTION PROTOTYPES                                                   *
*******************************************************************************/

/*******************************************************************************
* PUBLIC FUNCTION: vInitQuat
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Initialize the quaternion to the value sampled during start up.
* This function must be called after the sensors are initialized.
*
*******************************************************************************/
void vInitQuat(void);



/*******************************************************************************
* TASK: taskQuatLoop
*
* DESCRIPTIONS:
* This task is the main loop of the quaternion and will get executed every 5ms (200Hz).
*
*******************************************************************************/
portTASK_FUNCTION_PROTO(taskQuatLoop, pvParameters);



#endif
